<?
include_once("/var/www/html/new/com.inc.php");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));


// $mobile = '13348256746';
$salerid = $_REQUEST['salerid'] + 0;// 商户ID
$voucher = $_REQUEST['voucher'] + 0;// 凭证码
$code = $mobile = $idCard = '';
if(strlen($voucher)==6){// 凭证码
	$code = $voucher;
	$verify = new PsVerfiy($s, $salerid, $voucher);
	echo json_encode($verify->information());
	
	
}elseif(strlen($voucher)==11 && is_numeric($voucher)){// 手机号
	$mobile = $voucher;
	$verify = new PsVerfiy($s, $salerid);
	echo json_encode($verify->information($salerid, $mobile));
}else{// 身份证
	$idCard = $voucher;
}






$method = 999;
switch($method){
	case '':break;
	case '':break;
	default:break;
}



class PsVerfiy{
	
	public $inside = null;// 内部接口
	public $salerid = 0;// 景区编码
	public $ordernum = '';// 订单号
	public $voucher = 0;
	public function __construct($s, $salerid=0, $voucher=0){
		$this->inside = $s;
		$this->salerid = $salerid;
		$this->voucher = $voucher;
	}
	
	// 通过商户6位账号和凭证码反查订单
	public function reverse($salerid=0, $voucher=0, $sid=0){
		if($salerid==0) $salerid = $this->salerid;
		if($voucher==0) $voucher = $this->voucher;
		if($salerid==0 || $voucher==0) return '';
		if($sid==0) $sid = $_SESSION['sid'];
		$ordernum = $this->inside->Code_Verify_Order($salerid, $voucher, $sid);
		$this->ordernum = $ordernum;
		return $ordernum;
	}
	
	
	// 获取订单信息
	public function information($salerid=0, $mobile='', $orderId=''){
		
		$sendData = array();
		$status = ($_SESSION['sid']==1) ? '0|2':'0';// 0 未验证 2 已过期
		if($salerid==0) $salerid = $this->salerid;
		if($mobile=='') $orderId = $this->reverse();// 如果没有传手机号，按订单查找
		if($salerid==0 && $orderId=='') return $sendData;
		$xmlStr = $this->inside->Order_Globle_Search($salerid,'','','','','','','','','','','',$orderId,'',$mobile, $orderStatus,'','',1,0,0,100,'','','','','','','','','',0,0);
		$simxml = simplexml_load_string($xmlStr);
		foreach($simxml->Rec as $order){
			if($order->UUconcat_id!=0){// 联票
				$concat = (string)$order->UUconcat_id;
				$ordernum = (string)$order->UUordernum;
				$orderId = ($concat==$ordernum) ? $ordernum:$concat;
				if($concat!=$ordernum && !isset($sendData[$orderId]['ordernum'])) continue;
			}else{
				$orderId = (string)$order->UUordernum;
			}

			if(!isset($sendData[$orderId]['ordernum'])){
				$sendData[$orderId]['ordernum'] = $orderId;//  订单号
				$sendData[$orderId]['ordername'] = (string)$simxml->Rec->UUordername;// 取票人姓名
				$sendData[$orderId]['ordertel'] = (string)$simxml->Rec->UUordertel;// 取票人手机
				$sendData[$orderId]['ordertime'] = (string)$simxml->Rec->UUordertime;// 下单时间
				$sendData[$orderId]['begintime'] = (string)$simxml->Rec->UUbegintime;// 游玩时间
				$sendData[$orderId]['pmode'] = (string)$simxml->Rec->UUpmode;
			}
			
			$sendData[$orderId]['tickets'][] = array(
				'name'=>(string)$order->UUttitle,
				'tnum'=>(int)$order->UUtnum,
			);
		}
		return $sendData;
	}
}
?>